package com.revenant.driver.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.revenant.driver.R;
import com.revenant.driver.adapter.PersonalCommentAdapter;
import com.revenant.driver.adapter.PersonalCommentNewAdapter;
import com.revenant.driver.base.BaseActivity;
import com.revenant.driver.bean.PersonalCommentShowBean;
import com.revenant.driver.utils.GsonUtil;
import com.revenant.driver.utils.Utils;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.revenant.driver.utils.Constants.Comment_PerSonal_Show;

public class OderDetailPersonalActivity extends BaseActivity {


    @BindView(R.id.head)
    ImageView head;
    @BindView(R.id.new_account_aphone)
    TextView newAccountAphone;
    @BindView(R.id.new_account_bstatus)
    TextView newAccountBstatus;
    @BindView(R.id.new_account_cdealcount)
    TextView newAccountCdealcount;
    @BindView(R.id.new_account_dsend)
    TextView newAccountDsend;
    @BindView(R.id.new_account_eappraise)
    TextView newAccountEappraise;
    @BindView(R.id.new_account_fcredit)
    TextView newAccountFcredit;
    @BindView(R.id.new_account_ggoodreputation)
    TextView newAccountGgoodreputation;
    @BindView(R.id.new_account_hid)
    TextView newAccountHid;
    @BindView(R.id.new_account_icompanyname)
    TextView newAccountIcompanyname;
    @BindView(R.id.new_account_jcompanyaddress)
    TextView newAccountJcompanyaddress;
    @BindView(R.id.new_account_recyclerview)
    RecyclerView newAccountRecyclerview;
    @BindView(R.id.new_account_refresh)
    SmartRefreshLayout smartrefresh;

    PersonalCommentNewAdapter personalCommentAdapter;
    List<String> stringList= Arrays.asList(
            "货主未认证",
            "货主已认证",
            "企业升级待审核",
            "企业认证通过 ",
            "企业认证不通过",
            "司机认证通过",
            "司机认证不通过",
            "司机待审核",
            "司机未审核",
            "个人待审核"
    );
    private Context context;
    private String phone = "";

    @Override
    public int getContentViewResId() {
        return R.layout.activity_oder_detail_personal;
    }

    @Override
    public void initView() {
        context = this;
        showrighttext(true);
        setrightTitle("联系电话");
        setcenterTitle("货主资料");
        personalCommentAdapter = new PersonalCommentNewAdapter();
        newAccountRecyclerview.setAdapter(personalCommentAdapter);
        newAccountRecyclerview.setLayoutManager(new LinearLayoutManager(context));
    }


    @Override
    public void leftbarclick() {
        super.leftbarclick();
        finish();
    }

    @Override
    public void rightbarclick() {
        super.rightbarclick();
        if (!phone.isEmpty()){
            Utils.callPhone(OderDetailPersonalActivity.this, phone);
        }
    }

    @Override
    public void initData() {
        String bundleid = getIntent().getStringExtra("oppositeid");
        getaddDetail(bundleid);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    private void getaddDetail(String id) {
        OkGo.<String>get(Comment_PerSonal_Show)

                .params("id", id)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        if (response.code() == 200) {
                            PersonalCommentShowBean personal = GsonUtil.parseJsonWithGson(response.body(), PersonalCommentShowBean.class);
                            if (Integer.valueOf(personal.getCode()) == 0) {

                                Glide.with(context).load(personal.getData().getPhoto()).placeholder(R.mipmap.picture).into(head);

                                StringBuilder stringBuilder = new StringBuilder(personal.getData().getPhone());
                                phone = personal.getData().getPhone();
                                StringBuilder replacetext = stringBuilder.replace(3, 7, "****");
                                newAccountBstatus.setText(String.valueOf(stringList.get(personal.getData().getStatus()==4?1:personal.getData().getStatus())));
                                newAccountAphone.setText(String.valueOf(replacetext));
                                newAccountDsend.setText(String.valueOf(personal.getData().getGoodsount()));
                                newAccountEappraise.setText(String.valueOf(personal.getData().getEvaluateCount()));
                                newAccountCdealcount.setText(String.valueOf(String.valueOf(personal.getData().getOrderCount())));
                                newAccountEappraise.setText(String.valueOf(String.valueOf(personal.getData().getEvaluateCount()) + "条"));
                                newAccountFcredit.setText(String.valueOf(String.valueOf(personal.getData().getLevel())));
                                newAccountGgoodreputation.setText(String.valueOf(String.valueOf(personal.getData().getRate())));
                                newAccountHid.setText(String.valueOf(String.valueOf(personal.getData().getUserName())));
                                if (!(personal.getData().getStatus()==4||personal.getData().getStatus()==2)){
                                    newAccountIcompanyname.setText(String.valueOf(String.valueOf(personal.getData().getCompanyName())));
                                    newAccountJcompanyaddress.setText(String.valueOf(String.valueOf(personal.getData().getCompanyAddress())));
                                }


                                personalCommentAdapter.setNewData(personal.getData().getList());
                                smartrefresh.finishRefresh();

                            }

                        }

                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast(response.message());
                    }
                });
    }
}
